package com.atguigu.tingshu.album.api;

import com.atguigu.tingshu.album.service.AlbumInfoService;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.common.util.AuthContextHolder;
import com.atguigu.tingshu.model.album.AlbumInfo;
import com.atguigu.tingshu.query.album.AlbumInfoQuery;
import com.atguigu.tingshu.vo.album.AlbumInfoVo;
import com.atguigu.tingshu.vo.album.AlbumListVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tencentcloudapi.live.v20180801.models.AddLiveWatermarkRequest;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;


import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Tag(name = "专辑管理")
@RestController
@RequestMapping("api/album/albumInfo")
@SuppressWarnings({"all"})
public class AlbumInfoApiController {

    @Autowired
    private AlbumInfoService albumInfoService;

    @Operation(summary = "新增专辑")
    @PostMapping("saveAlbumInfo")
    public Result saveAlbumInfo(@RequestBody @Validated AlbumInfoVo albumInfoVo) {
        Long userId = AuthContextHolder.getUserId();
        albumInfoService.saveAlbumInfo(albumInfoVo, userId);
        return Result.ok();
    }

    @Operation(summary = "获取当前用户专辑分页列表")
    @PostMapping("findUserAlbumPage")
    public Result findUserAlbumPage(@Parameter(name = "page", description = "当前页码", required = true)
                                    @PathVariable Long pageNo,
                                                 @Parameter(name = "limit", description = "每页记录数", required = true)
                                    @PathVariable Long pageSize,
                                                 @Parameter(name = "albumInfoQuery", description = "查询对象", required = false)
                                    @RequestBody AlbumInfoQuery albumInfoQuery
    ) {
        long userId = AuthContextHolder.getUserId() == null ? 1l : AuthContextHolder.getUserId();

        Page<AlbumListVo> albumListVoPage = new Page<>(pageNo,pageSize);

        IPage<AlbumListVo> iPage =albumInfoService.findUserAlbumPage(albumListVoPage,albumInfoQuery);

        return Result.ok(iPage);
    }

}

